package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.Notice
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.INoticeView
import de.baumann.browser.model.CenterModel
import de.baumann.browser.utils.isLogined

open class NoticePresenter<V : INoticeView> : BasePresenter<V>() {

    private var centerModel = CenterModel()

    fun getNotice() {
        if (!isLogined()) {
            return
        }

        this.centerModel.notice
                .subscribe(object : OdinObserver<List<Notice>>() {
                    override fun onSuccess(data: List<Notice>?) {
                        if (view != null && data != null) {
                            view.setNotices(data)
                        }
                    }
                })
    }

    fun noticeRead(noticeId: String) {
        this.centerModel.noticeRead(noticeId)
                .subscribe(object : OdinObserver<Any>() {
                    override fun onSuccess(data: Any?) {
                    }
                })
    }
}